import uuid
from typing import Any, TypeVar

from sqlalchemy import inspect

from recruit.adapter.database.models import Base, Resume

BaseModel = TypeVar('BaseModel', bound=Base)


def check_fields(fields: tuple[str, ...], model: type[Base]) -> None:
    inspector = inspect(model)
    fields_model = [column.name for column in inspector.columns]
    assert all(
        field in fields_model for field in fields
    )


def check_valid_data(model: Base, data: dict[str, Any]) -> None:
    for key, value in data.items():
        assert getattr(model, key) == value


def check_model_resume(
        model: type[BaseModel],
        data: dict[str, Any]
) -> None:
    assert issubclass(model, Base)
    _model = model(**data)
    check_valid_data(_model, data)
    resume = Resume(id=data['resume_id'], user_id=uuid.uuid4())
    _model.resume = resume
    assert isinstance(_model.resume, Resume)
    assert _model.resume.id == data['resume_id']


def get_model_resume(
        model: type[BaseModel],
        data: dict[str, Any]
) -> BaseModel:
    _model = model(**data)
    _model.resume_id = None
    return _model
